﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace lchealthy
{
    public partial class reg : Form
    {
        public reg()
        {
            InitializeComponent();
        }

        private void reg_Load(object sender, EventArgs e)
        {
            Computer com = new Computer();

            this.textBox2.Text = Computer.EncryptDES(com.GetDiskID().ToString(), "48665218").ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Computer com = new Computer();
            string c = "jinan123";
            string suiji = Computer.EncryptDES(com.GetDiskID().ToString(), c);
            if (this.textBox1.Text.Trim() == suiji)
            {
                MessageBox.Show("OK");
                //if (File.Exists("code.txt"))
                //{
                //    FileStream f = File.OpenRead("code.txt");
                //    StreamReader sw = new StreamReader(f, System.Text.Encoding.Default);

                //    while (!sw.EndOfStream)
                //    {
                //        string t = sw.ReadLine();
                //        string[] m = t.Split(',');
                //        ListViewItem lvt = new ListViewItem(new string[] { m[0], m[1], m[2] });
                //        if (m.Length == 4) lvt.Tag = m[3];
                //        this.listView1.Items.Add(lvt);
                //    }
                //    //f.CreateText(ipad.Text);

                //    sw.Close();
                //    f.Close();
                //}
                //FileInfo f = new FileInfo("code.txt");
                if (!File.Exists("code.txt"))
                    File.Create("code.txt");


                FileStream fs = new FileStream("code.txt", FileMode.OpenOrCreate);//File.OpenWrite("ip.txt");

                StreamWriter sw = new StreamWriter(fs);
                sw.WriteLine(textBox1.Text.Trim());
                //f.CreateText(ipad.Text);
                sw.Flush();
                sw.Close();
                fs.Close();
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("注册码不对！，请联系AnySoft@sina.cn!");
            }

        }

        private void reg_FormClosing(object sender, FormClosingEventArgs e)
        {
            //Application.Exit();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
